def solution(nums: list):
    """
    :param nums:
    :return:
    """
    nums.sort(key=lambda x: x[0])
    result = 0
    max_right = nums[0][1]
    left = nums[0][0]
    for i in range(len(nums)):
        if nums[i][0] <= max_right:
            max_right = max(max_right, nums[i][1])
        else:
            result += max_right - left
            left = nums[i][0]
            max_right = nums[i][1]
    result += max_right - left
    return result


if __name__ == '__main__':
    print(solution([[1, 5], [5, 10]]))
